package com.sumer.psychology.photo.infrastructure.messaging.rabbitmq;

import com.sumer.psychology.common.port.adapter.messaging.Exchanges;
import com.sumer.psychology.common.port.adapter.messaging.rabbitmq.ExchangeListener;
import com.sumer.psychology.photo.infrastructure.persistence.mongo.MongoAlbumRepository;

/**
 * 相册更改监听
 * <p/>
 * User: zhenguang.zhu
 * Date: 2014/10/29
 * Time: 15:29
 */
public class AlbumChangedEventListener extends ExchangeListener {
    private MongoAlbumRepository mongoAlbumRepository;

    public AlbumChangedEventListener(MongoAlbumRepository mongoAlbumRepository) {
        this.mongoAlbumRepository = mongoAlbumRepository;
    }

    @Override
    protected String exchangeName() {
        return Exchanges.DEFAULT_EXCHANGE_NAME;
    }

    @Override
    protected void filteredDispatch(String aType, String aTextMessage) {
        mongoAlbumRepository().change(aTextMessage);
    }

    @Override
    protected String[] listensTo() {
        return new String[]{"com.sumer.psychology.photo.domain.model.AlbumChangedEvent"};
    }

    private MongoAlbumRepository mongoAlbumRepository() {
        return mongoAlbumRepository;
    }
}
